<template>
	<view class="sp-page sp-user__create">
		<view class="sp-user__create-item">
			<label>旧密码</label>
			<input v-model="form.old_password" placeholder="请输入旧密码" type="password">
		</view>
		<view class="sp-user__create-item">
			<label>新密码</label>
			<input v-model="form.new_password" placeholder="请输入新密码" type="password">
		</view>
		<view class="sp-user__create-item">
			<label>重复新密码</label>
			<input v-model="new_password" placeholder="请重复输入新密码" type="password">
		</view>
		<view class="sp-room__submit">
			<button @click="setUser">保存</button>
		</view>
	</view>
</template>

<script>
	import { setChangePassword } from '@/api/task.js'
	
	export default {
		name: 'spCreateForm',
		data() {
			return {
				form: {
					old_password: '',
					new_password: ''
				},
				new_password: ''
			}
		},
		mounted() {},
		methods: {
			setUser() {
				if (this.form.old_password === '') {
					this.$u.toast('旧密码不能为空')
					return false
				}
				if (this.form.new_password === '') {
					this.$u.toast('新密码不能为空')
					return false
				}
				if (this.form.new_password != this.new_password) {
					this.$u.toast('两次密码输入不一致')
					return false
				}
				setChangePassword(this.form).then(res => {
					if (res) {
						this.$u.toast('修改成功')
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/user/index'
							})
						}, 1500)
					} else {
						this.$u.toast('修改失败')
					}
				}).catch(err => {
					this.$u.toast('修改失败')
				})
			}
		}
	}
</script>

<style lang="scss">
	.sp-user__create {
		padding: 0 20rpx;
		background: #fff;
		
		&- {
			
			&item {
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid #eee;
				
				label {
					display: block;
					font-size: 24rpx;
					color: #666;
					padding: 20rpx 0;
				}
				
				input {
					border: 0;
					height: 66rpx;
					font-size: 28rpx;
				}
			}
		}
	}
</style>
